package threadx;

public class Test2 {
    public static void main(String[] args) {
        MyTickets target = new MyTickets();
        for (int i = 0; i < 4; i++) {//利用4个线程执行同一个任务
            new Thread(target).start();
        }
    }
}

class MyTickets implements Runnable{
    int tickets = 100;//定义变量，记录票数
    @Override
    public void run() {
        while (true){
            if(tickets>0){
                //问题1：超卖
                //问题2：重卖
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() +"~~"+tickets--);
            }else{
                break;
            }
        }
    }
}